#!/usr/bin/env python3
"""
诊断批量删除API问题
"""
import sys
import os
import django

# 设置Django环境
sys.path.insert(0, '/aiops/backend')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
django.setup()

from cmdb.views import AuditLogViewSet
from rest_framework.routers import DefaultRouter

# 创建router并注册
router = DefaultRouter()
router.register(r'audit-logs', AuditLogViewSet, basename='audit-log')

print("=" * 60)
print("DRF Router 生成的URL列表")
print("=" * 60)
print()

for pattern in router.urls:
    print(f"URL Pattern: {pattern.pattern}")
    print(f"  Name: {pattern.name}")
    if hasattr(pattern.callback, 'actions'):
        print(f"  Actions: {pattern.callback.actions}")
    print()

print("=" * 60)
print("AuditLogViewSet 的自定义 actions")
print("=" * 60)
print()

# 检查ViewSet的所有方法
for attr_name in dir(AuditLogViewSet):
    attr = getattr(AuditLogViewSet, attr_name)
    if hasattr(attr, 'mapping'):
        print(f"Action: {attr_name}")
        print(f"  Mapping: {attr.mapping}")
        print(f"  Detail: {attr.detail}")
        print()

print("=" * 60)
print("测试结果")
print("=" * 60)

# 检查bulk_delete是否存在
if hasattr(AuditLogViewSet, 'bulk_delete'):
    print("✅ bulk_delete 方法存在")
    bulk_delete = getattr(AuditLogViewSet, 'bulk_delete')
    if hasattr(bulk_delete, 'mapping'):
        print(f"   HTTP方法: {bulk_delete.mapping}")
        print(f"   是否detail: {bulk_delete.detail}")
else:
    print("❌ bulk_delete 方法不存在")

print()

# 检查bulk_resolve是否存在
if hasattr(AuditLogViewSet, 'bulk_resolve'):
    print("✅ bulk_resolve 方法存在")
    bulk_resolve = getattr(AuditLogViewSet, 'bulk_resolve')
    if hasattr(bulk_resolve, 'mapping'):
        print(f"   HTTP方法: {bulk_resolve.mapping}")
        print(f"   是否detail: {bulk_resolve.detail}")
else:
    print("❌ bulk_resolve 方法不存在")

print()
print("=" * 60)
